export default {
    timestampToTime(timestamp,f){
        if(!timestamp){
            return ''
        }
        let date = new Date(parseInt(timestamp));
        let Y = date.getFullYear() + '-';
        let M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        let D = (date.getDate()>=10?date.getDate():'0'+date.getDate());
        let h = " "+(date.getHours()>=10?date.getHours():'0'+date.getHours()) + ':';
        let m = (date.getMinutes()>=10?date.getMinutes():'0'+date.getMinutes()) + ':';
        let s = date.getSeconds()>=10?date.getSeconds():'0'+date.getSeconds();
        if(f==2){
            return M+D
        }else if(f == 3){
            return Y+M+D;
        }else if(f==5){
            return Y+M+D+h+m+s;
        }
    }
}

export function perceptiontime(time){
    let nowtime = new Date().getTime();
    let date = new Date(parseInt(time));
    let v=nowtime-time;
    let Y = date.getFullYear();
    let M = date.getMonth()+1;
    let D = date.getDate();
    let result ;
    if(v<60*1000){
        result="1 分钟前"
    }else if(v<60*60*1000){
        /*
        * 10:59  11:20  21 80-59=21
        * 10:01  10:59  58 59-1=58
        * 10:01  11:00  59
        *
        * */
        /*if(new Date(nowtime).getMinutes()>m){
            //当前分钟大于原来的分钟 小时应该一样大
            m=new Date(nowtime).getMinutes()-m;
        }else{
            //小时不一样了  所以分钟需要+60
            m=new Date(nowtime).getMinutes()+60-m;
        }*/
        result=(v/1000/60).toFixed(0)+" 分钟前"
    }else if(v<60*60*24*1000){
        result=(v/1000/60/60).toFixed(0)+" 小时前"
    }else if(v<60*60*24*360*1000){
        result=(M<10?"0"+M:M)+"-"+(D<10?"0"+D:D)
    }else{
        result=Y+"-"+(M<10?"0"+M:M)+"-"+(D<10?"0"+D:D)
    }
    return result;
    /*let Y = date.getFullYear() + '-';

    if(Y===nowtime.getFullYear()){
        //如果是当年的就不显示年
        let M = date.getMonth()+1 + '-';
        let D = (date.getDate()>=10?date.getDate():'0'+date.getDate());
        let h = " "+(date.getHours()>=10?date.getHours():'0'+date.getHours()) + ':';
        let m = (date.getMinutes()>=10?date.getMinutes():'0'+date.getMinutes()) + ':';
        let s = date.getSeconds()>=10?date.getSeconds():'0'+date.getSeconds();
        result = M+D;
    }*/

}